from peewee import MySQLDatabase, Model, CharField, FloatField, CompositeKey

# 创建MySQL数据库连接 test
# db = MySQLDatabase('demo1', user='root', password='root', host='192.168.3.42', port=3306)
# 创建MySQL数据库连接 安吉
db = MySQLDatabase('ajwater', user='xtxzh', password='jaU#K*rYyK&Z=jV#MTM', host='rm-5bg563t7zn4g7zd4g.mysql.rds.anjinewsgrp-ops.net', port=3306)

fieldsReservoirNameList = ["resCode", "resName", "manLev", "adcd", "engScal", "totCap", "tongTime", "isDelete", "techIsEnable"]


class ReservoirNameList(Model):
    resCode = CharField(column_name="res_code", primary_key=True, max_length=50)
    resName = CharField(column_name="res_name", null=True, max_length=255)
    # conProCode =  CharField(column_name="conProCode", max_length=50, primary_key=True)
    manLev = CharField(column_name="man_lev", null=True, max_length=50)
    adcd = CharField(column_name="adcd", null=True, max_length=50)
    engScal = CharField(column_name="eng_scal", null=True, max_length=50)
    totCap = FloatField(column_name="tot_cap", null=True)
    tongTime = CharField(column_name="tong_time", null=True, max_length=50)
    isDelete = CharField(column_name="is_delete", null=True, max_length=50)
    techIsEnable = CharField(column_name="tech_is_enable", null=True, max_length=50)

    class Meta:
        database = db
        table_name = "reservoir_namelist"


fieldsReservoirBaseInfo = ["id", "resName", "conProCode", "manLev", "adCode", "adcd", "resLoc", "resLong", "resLat", "relatedCounties", "waterSystemName",
                           "engScal", "engGrad", "rcdsArea", "mstreamLen", "dsflst", "chflst", "dwchsfds", "dswlel", "wlel", "dsemel", "emel", "totCap",
                           "chfllv", "desFlStag", "uppLevFlco", "flcoCap", "normWatLev", "normPoolStagCap", "floodWatLev", "reservoirStorageCurve", "hshgwtlv",
                           "hisMaxOutFlow", "mainFunc", "cnflMjob", "dsirar", "annWain", "avanenot", "bizTime", "isDelete", "initTime", "tongTime", "op",
                           "ddadMulAverRuof", "storFlCap", "benResCap", "deadLev", "deadCap", "chflMaxDflow", "desFlMaxDflow", "hhwltm", "hmerfl", "hmerflt",
                           "hmorflt", "effIrrArea", "resType", "riverMaxDflow", "overfolwCrestHeight", "holebottomHeight", "maxWaterSupply", "hlfol",
                           "techIsEnable"]


class ReservoirBaseInfo(Model):
    id = CharField(column_name="res_code", primary_key=True, max_length=50)
    resName = CharField(column_name="res_name", null=True, max_length=255)
    conProCode = CharField(column_name="con_pro_code", null=True, max_length=50)
    manLev = CharField(column_name="man_lev", null=True, max_length=50)
    adCode = CharField(column_name="ad_code", null=True, max_length=50)
    adcd = CharField(column_name="adcd", null=True, max_length=50)
    resLoc = CharField(column_name="res_loc", null=True, max_length=255)
    resLong = FloatField(column_name="res_long", null=True)
    resLat = FloatField(column_name="res_lat", null=True)
    relatedCounties = CharField(column_name="related_counties", null=True, max_length=255)
    waterSystemName = CharField(column_name="water_system_name", null=True, max_length=255)
    engScal = CharField(column_name="eng_scal", null=True, max_length=50)
    engGrad = CharField(column_name="eng_grad", max_length=50, null=True)
    rcdsArea = FloatField(column_name="rcds_area", null=True)
    mstreamLen = FloatField(column_name="mstream_len", null=True)
    dsflst = FloatField(column_name="dsflst", null=True)
    chflst = FloatField(column_name="chflst", null=True)
    dwchsfds = FloatField(column_name="dwchsfds", null=True)
    dswlel = FloatField(column_name="dswlel", null=True)
    wlel = FloatField(column_name="wlel", null=True)
    dsemel = FloatField(column_name="dsemel", null=True)
    emel = FloatField(column_name="emel", null=True)
    totCap = FloatField(column_name="tot_cap", null=True)
    chfllv = FloatField(column_name="chfllv", null=True)
    desFlStag = FloatField(column_name="des_fl_stag", null=True)
    # designFloodCv =FloatField(column_name="des_fl_cv", )
    uppLevFlco = FloatField(column_name="upp_lev_flco", null=True)
    # fhlvcv =FloatField(column_name="tot_cap", )
    flcoCap = FloatField(column_name="flco_cap", null=True)
    normWatLev = FloatField(column_name="norm_wat_lev", null=True)
    normPoolStagCap = FloatField(column_name="norm_pool_stag_cap", null=True)
    floodWatLev = FloatField(column_name="flood_wat_lev", null=True)
    reservoirStorageCurve = FloatField(column_name="reservoir_storage_curve", null=True)
    hshgwtlv = FloatField(column_name="hshgwtlv", null=True)
    hisMaxOutFlow = FloatField(column_name="his_max_out_flow", null=True)
    mainFunc = CharField(column_name="main_func", null=True, max_length=255)
    cnflMjob = CharField(column_name="cnfl_mjob", null=True, max_length=255)
    dsirar = FloatField(column_name="dsirar", null=True)
    annWain = FloatField(column_name="ann_wain", null=True)
    avanenot = FloatField(column_name="avanenot", null=True)
    bizTime = CharField(column_name="biz_time", null=True, max_length=50)
    isDelete = CharField(column_name="is_delete", null=True, max_length=50)
    initTime = CharField(column_name="init_time", null=True, max_length=50)
    tongTime = CharField(column_name="tong_time", null=True, max_length=50)
    op = CharField(column_name="op", null=True, max_length=10)
    ddadMulAverRuof = FloatField(column_name="ddad_mul_aver_ruof", null=True)
    storFlCap = FloatField(column_name="stor_fl_cap", null=True)
    benResCap = FloatField(column_name="ben_res_cap", null=True)
    deadLev = FloatField(column_name="dead_lev", null=True)
    deadCap = FloatField(column_name="dead_cap", null=True)
    chflMaxDflow = FloatField(column_name="chfl_max_dflow", null=True)
    desFlMaxDflow = FloatField(column_name="des_fl_max_dflow", null=True)
    hhwltm = CharField(column_name="hhwltm", null=True, max_length=50)
    hmerfl = FloatField(column_name="hmerfl", null=True)
    hmerflt = CharField(column_name="hmerflt", null=True, max_length=50)
    hmorflt = CharField(column_name="hmorflt", null=True, max_length=50)
    effIrrArea = FloatField(column_name="eff_irr_area", null=True)
    resType = CharField(column_name="res_type", null=True, max_length=255)
    riverMaxDflow = FloatField(column_name="river_max_dflow", null=True)
    overfolwCrestHeight = FloatField(column_name="overfolw_crest_height", null=True)
    holebottomHeight = FloatField(column_name="holebottom_height", null=True)
    maxWaterSupply = FloatField(column_name="max_water_supply", null=True)
    hlfol = FloatField(column_name="hlfol", null=True)
    # limitcurrenty = FloatField(column_name="tot_cap", )
    techIsEnable = CharField(column_name="tech_is_enable", null=True, max_length=255)

    class Meta:
        database = db
        table_name = "reservoir_baseinfo"


fieldsRiverWaterLevel = ["stcd", "tm", "z", "w"]


# RiverWaterLevel 河道水位监测数据
class RiverWaterLevel(Model):
    stcd = CharField(column_name="stcd", max_length=50)
    tm = CharField(column_name="tm", max_length=50)
    z = FloatField(column_name="z", null=True)
    w = FloatField(column_name="w", null=True)

    class Meta:
        primary_key = CompositeKey('stcd', 'tm')
        # indexes = ((('stcd', 'tm'), True),)
        database = db
        table_name = "river_waterlevel"
